package com.xhs.controller;

import com.xhs.dto.request.GetUserParam;
import com.xhs.entity.SysUserEntity;
import com.xhs.message.ReturnResult;
import com.xhs.service.SysUserService;
import com.xhs.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @desc:
 * @projectName: spring-boot-redis
 * @author: xhs
 * @date: 2024-06-21 021 14:44
 * @version: JDK 1.8
 */
@Slf4j
@RestController
@RequestMapping("/redis")
public class TestController {

    @Resource
    private SysUserService userService;
    @Resource
    private TestService testService;

    /**
     * 获取所有的key
     *
     * @return ReturnResult<Object>
     */
    @GetMapping("/getKey")
    public ReturnResult<Object> getKey() {
        return userService.getKey();
    }

    /**
     * 保存string类型的数据
     *
     * @return ReturnResult<Object>
     */
    @PostMapping("/saveString")
    public ReturnResult<Object> saveString() {
        return userService.saveToString();
    }

    /**
     * 获取sring类型的数据
     *
     * @return ReturnResult<Object>
     */
    @GetMapping("/getString")
    public ReturnResult<Object> getString() {
        return userService.getString();
    }

    /**
     * 保存list类型的数据
     *
     * @return ReturnResult<Object>
     */
    @PostMapping("/saveToList")
    public ReturnResult<Object> saveToList() {
        return userService.saveToList();
    }

    /**
     * 获取List类型的数据
     *
     * @return ReturnResult<Object>
     */
    @GetMapping("/getList")
    public ReturnResult<Object> getList() {
        return userService.getList();
    }

    /**
     * 保存map类型的数据
     *
     * @return ReturnResult<Object>
     */
    @PostMapping("/saveToMap")
    public ReturnResult<Object> saveToMap() {
        return userService.saveToMap();
    }

    /**
     * 获取map类型的数据
     *
     * @return ReturnResult<Object>
     */
    @GetMapping("/getMap")
    public ReturnResult<Object> getMap() {
        return userService.getFromMap();
    }

    /**
     * 删除Key
     *
     * @return ReturnResult<Object>
     */
    @PostMapping("/delKey")
    public ReturnResult<Object> delKey() {
        return userService.delete();
    }

    /**
     * 保存数据
     *
     * @param name 名字
     * @return ReturnResult<Object>
     */
    @PostMapping("/setName")
    public ReturnResult<Object> setName(String name) {
        return userService.setName(name);
    }

    /**
     * 根据key删除数据
     *
     * @param key key
     * @return ReturnResult<Object>
     */
    @GetMapping("/delKeyByName")
    public ReturnResult<Object> delKeyByName(String key) {
        return userService.delKeyByName(key);
    }


    /**
     * 查询用户信息
     *
     * @param param 入参
     * @return ReturnResult<SysUserEntity>
     */
    @PostMapping("/getUserInfo")
    private ReturnResult<SysUserEntity> getUserInfo(@Valid @RequestBody GetUserParam param) {
        return userService.getUserInfo(param);
    }
    /**
     * 根据手机号查询用户信息
     *
     * @param param 入参
     * @return ReturnResult<Object>
     */
    @PostMapping("/getCacheUser")
    public ReturnResult<Object> getCacheUser(@Valid @RequestBody GetUserParam param) {
        return testService.getCacheUser(param);
    }
}
